//////////////////////
use "data.dta", clear

set more off
cap file close myfile
local name="Table9.tex"
file open myfile using "`name'", write text replace
file write myfile "\begin{table}[ht]" _n
file write myfile "	\centering" _n
file write myfile "\begin{tabular}{l ccccccc}" _n
file write myfile "\toprule" _n

	local line1="Effect of Scoring"
	local line2se="{\footnotesize SE}"
	local line3="{\footnotesize N}"
	foreach var in note{
		di "`var'"
		di "`effectscore'"
		foreach var2 in previousnote sumnoteseason mv pplayerwin All{
			if "`var2'"!="All"{
			teffects nnmatch (note absx2 absy2 `var2') (postin)  ///
				,  nneighbor(1)  biasadj(absx2 absy2 `var2')
			}
			if "`var2'"=="All"{
				teffects nnmatch (note absx2 absy2 previousnote sumnoteseason mv pplayerwin) (postin)  ///
					,  nneighbor(1)  biasadj(absx2 absy2  previousnote sumnoteseason mv pplayerwin)  
			}
			matrix B=e(b)
			matrix V=e(V)
			local b1:di%4.3f B[1,1]
			if "`var'"=="minplay"{
				local b1:di%4.2f B[1,1]
			}
			local p1=2*(1-normal(abs(B[1,1]/sqrt(V[1,1]))))
			local p1:di%4.3f `p1'
			local se=sqrt(V[1,1])
			local se:di%4.3f `se'
			local star1=""
			if `p1'<0.1{
				local star1="^{\dag}"
			}
			if `p1'<0.05{
				local star1="^{*}"
			}
			if `p1'<0.01{
				local star1="^{**}"
			}
			if `p1'<0.001{
				local star1="^{***}"
				local p1="<0.001"
			}
			local N1=e(N)
			local N1: di%6.0fc `N1'
			
			local line1="`line1'"+" & $"+"`b1'"+"`star1'"+" $ "
			local line2se="`line2se'"+" & "+"\footnotesize{"+"`se'"+"}"+"  "
			local line3="`line3'"+" & "+"\footnotesize{"+"`N1'"+"}"+"  "
		}
	}
	file write myfile "`line1'" "\\"  _n 
	file write myfile "`line2se'" "\\"  _n
	file write myfile "`line3'" "\\"  _n 
	
file write myfile "\midrule"  _n
file write myfile "\textbf{Variables used for matching:}\\"  _n
file write myfile "\\"  _n
file write myfile "Spatial coordinates & \checkmark &  \checkmark	& \checkmark &  \checkmark  &  \checkmark   \\"  _n
file write myfile "Rating $ _{t-1} $ & \checkmark &  	&  &   &  \checkmark \\"  _n
file write myfile "Av. rating since start season&  & \checkmark 	&  &   &  \checkmark \\"  _n
file write myfile "Players' market value &  &  	& \checkmark &   &  \checkmark \\"  _n
file write myfile "Ex-ante probability to win &  &  	&  & \checkmark  &  \checkmark \\"  _n
file write myfile "\bottomrule"  _n
file write myfile "\end{tabular}"  _n
file write myfile "\end{table}"  _n
file close myfile
	//////////////

